package com.polarrose.wsf.client;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

public class Invocation<T> {

	private String endpoint;
	private String action;
	private String version;
	private Map<String, String> parameters = new HashMap<String, String>();
	private ResultTransformer<T> resultTransformer;

	public Invocation(String endpoint, String action, String version, Map<String, String> parameters, ResultTransformer<T> resultTransformer) {
		this.endpoint = endpoint;
		this.action = action;
		this.version = version;
		this.parameters = parameters;
		this.resultTransformer = resultTransformer;
	}

	public Invocation(String endpoint, String action, String version, ResultTransformer<T> resultTransformer) {
		this.endpoint = endpoint;
		this.action = action;
		this.version = version;
		this.resultTransformer = resultTransformer;
	}

	
	public Invocation() {
	}

	public String getEndpoint() {
		return endpoint;
	}

	public String getAction() {
		return action;
	}

	public String getVersion() {
		return version;
	}

	public Map<String, String> getParameters() {
		if (parameters == null) {
			this.parameters = new HashMap<String, String>();
		}
		return parameters;
	}

	public ResultTransformer<T> getResultTransformer() {
		return resultTransformer;
	}

	/**
	 * 
	 * @return
	 * @throws HttpProtocolException
	 */
	public T invoke() throws HttpProtocolException {
		return null;
	}

	@Override
	public String toString() {
		StringBuilder buff = new StringBuilder();
		buff.append("Invocation[");
		buff.append("action=").append(action).append(", ");
		buff.append("parameters=[");
		Map<String, String> parameters = getParameters();
		Iterator<String> iterator = parameters.keySet().iterator();
		while (iterator.hasNext()) {
			String key = (String) iterator.next();
			buff.append(key).append("=").append(parameters.get(key));
			if (iterator.hasNext()) {
				buff.append(", ");
			}
		}
		buff.append("], ");
		buff.append("endpoint=").append(endpoint).append(", ");
		buff.append("version=").append(version);
		buff.append("]");
		return buff.toString();
	}

}
